﻿using Model;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Util
{
    public class Common
    {
        public static ISqlSugarClient _db;
        public Common(ISqlSugarClient db)
        {
            _db = db;
        }

        public ConfigurationDao GetConfig()
        {
            ConfigurationDao dao = new ConfigurationDao();

            var list = _db.Queryable<tConfiguration>().ToList();
            if(list!=null && list.Count > 0)
            {
                dao.Lunch = list.Where(x => x.FCode == "Lunch").First().FCodeValue;
                dao.Dinner = list.Where(x => x.FCode == "Dinner").First().FCodeValue;
                dao.LunchStartScan = list.Where(x => x.FCode == "LunchStartScan").First().FCodeValue;
                dao.LunchEndScan = list.Where(x => x.FCode == "LunchEndScan").First().FCodeValue;
                dao.DinnerStartScan = list.Where(x => x.FCode == "DinnerStartScan").First().FCodeValue;
                dao.DinnerEndScan = list.Where(x => x.FCode == "DinnerEndScan").First().FCodeValue;
                dao.DinnerCost = list.Where(x => x.FCode == "DinnerCost").First().FCodeValue;
                dao.voluntarily = list.Where(x => x.FCode == "voluntarily").First().FCodeValue;
            }
            return dao;
        }
        public string GetDayOfWeek(DateTime date)
        {
            // CultureInfo.InvariantCulture 是一个不依赖于区域设置的文化信息对象  
            // 它总是以英文返回星期几的名称  
            return date.ToString("dddd");
        }
    }
}
